﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 售后客户管理
{
    public partial class FieldButtonContrl : UserControl
    {
        public FieldButtonContrl()
        {
            InitializeComponent();
            this.SizeChanged += new EventHandler(ContrlsSizeChanged);
            this.FontChanged += new EventHandler(ContrlsSizeChanged);
            this.Enter += FeildContrl_Enter;
            this.GotFocus += FeildContrl_Enter;
            //this.LostFocus += FeildContrl_Enter;
            this.button1.Visible = false;
            this.textBox1.KeyDown += new KeyEventHandler(NextContrl);
            this.FontChanged += FieldButtonContrl_FontChanged;
            this.textBox1.Font = this.Font;
        }

        private void FieldButtonContrl_FontChanged(object sender, EventArgs e)
        {
            this.textBox1.Font = this.Font;
            this.label1.Font = this.Font;
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            OnDoubleClick(e);
        }
        /// <summary>
        /// 填入值
        /// </summary>
        public override string Text
        {
            get { return this.textBox1.Text; }
            set { this.textBox1.Text = value; }
        }
        public string DefaultText
        {
            get { return this.textBox1.Text; }
            set { this.textBox1.Text = value; }
        }
        public bool TextReadOnly
        {
            get
            {
                _TextReadOnly = this.textBox1.ReadOnly;
                return _TextReadOnly;
            }
            set
            {
                _TextReadOnly = value;
                this.textBox1.ReadOnly = _TextReadOnly;
            }
        }
        private bool _TextReadOnly = false;
        public bool BtnEnabled
        {
            get { return this.button1.Enabled; }
            set { this.button1.Enabled = value; }
        }


        public bool BtnVisible
        {
            get { return this.button1.Visible; }
            set { this.button1.Visible = value; }
        }
        /// <summary>
        /// 显示名称
        /// </summary>
        public string NameText
        {
            get { return this.label1.Text; }
            set { this.label1.Text = value; }
        }
        /// <summary>
        /// 列属性
        /// </summary>
        public string Colname
        {
            get;
            set;
        }
        private void ContrlsSizeChanged(object sender, EventArgs e)
        {
            this.Size = new Size(this.Size.Width, Convert.ToInt32(this.textBox1.Font.Size * 3));
            this.textBox1.Size = new Size(this.Size.Width - this.label1.Width - this.textBox1.Height, this.textBox1.Font.Height + 5);
            this.button1.Size = new Size(this.textBox1.Height, this.textBox1.Height);
            this.button1.Location = new Point(this.textBox1.Size.Width + this.label1.Width, this.button1.Location.Y);
        }
        private void FeildContrl_Enter(object sender, EventArgs e)
        {
            this.textBox1.Focus();
        }
        private void NextContrl(object sender, KeyEventArgs e)
        {
            OnKeyDown(e);
            if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send("{Tab}");
            }
        }
        
    }
}
